var gulp = require('gulp'),
    sass = require('gulp-sass'),
    watch = require('gulp-watch'),
    browser = require('browser-sync'),
    imagemin = require('gulp-imagemin');
 
var path = {
    sass: 'src/sass/*.scss'
}
 
// 编译sass
gulp.task('sass', function(){
    gulp.src(path.sass)
        .pipe(sass())
        .pipe(gulp.dest('src/css/'));
});
 
// 压缩图片
gulp.task('imagemin', function(){
    gulp.src('src/images/*.{png,jpg,gif,ico}')
        .pipe(imagemin())
        .pipe(gulp.dest('src/img'));
});
 
// 自动刷新
var DEV = 'src';
gulp.task('serve', function() {
    browser.init({
        server: DEV + '/'
    });
    gulp.watch(DEV + '/*.html' ).on('change', browser.reload)
    gulp.watch(DEV + '/js/*.js').on('change', browser.reload)
    gulp.watch(DEV + '/css/*.css').on('change', browser.reload)
    gulp.watch(DEV + '/sass/*.scss').on('change', browser.reload)
});
 
gulp.task('watch', function(){
    gulp.watch(path.sass, ['sass']);
});
 
gulp.task('default', ['watch', 'serve']);